<%@ page import="ee.ttu.rakarh.model.data.entities.ItemType" %>
<jsp:useBean id="itemTypes" scope="request" type="java.util.Collection<ee.ttu.rakarh.model.data.entities.ItemType>" />

<%!
public static String iterate(java.util.Collection<ee.ttu.rakarh.model.data.entities.ItemType> types) {
String toRet = "<ul>";
	if (types.size() == 0)
		return  "";
	for (ItemType itemType : types) {
		Boolean hasSubTypes = itemType.getSubType().size() == 0 ? false : true;
		
		if(!hasSubTypes)
			toRet += "<li><a href=\"?a=kataloog&type=" + itemType.getId() + "\">";
		toRet += itemType.getTypeName();
		if(!hasSubTypes)
			toRet += "</a></li>";
		toRet += iterate(itemType.getSubType());
	}
	toRet += "</ul>";
	return toRet;

}
%>
<div id="catalog">
	<%out.print(iterate(itemTypes));%>
</div>